package com.ifast.asset.util;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class NewThreadPool {
    public static ExecutorService executorService = null;

    public static ExecutorService getExecutorService() {

        if (executorService == null){
            Lock lock = new ReentrantLock();
            synchronized (lock) {
                if (executorService == null) {

                    return newFixedThreadPool(5);
                } else {

                    return executorService;
                }
            }
        }else {
            return executorService;
        }
    }

    //创建FixedThreadPool
    public static ExecutorService newFixedThreadPool(int nThreads) {
        return new ThreadPoolExecutor(nThreads, nThreads,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>());
    }
}
